// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import iView from 'view-design'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

// import iView from 'iview'
import i18n from '@/locale'
import config from '@/config'
import importDirective from '@/directive'
import { axiosHttp } from "@/libs/request";

import { directive as clickOutside } from 'v-click-outside-x'
import installPlugin from '@/plugin'
import './index.less'
import '@/assets/icons/iconfont.css'
import TreeTable from 'tree-table-vue'
import VOrgTree from 'v-org-tree'
import 'v-org-tree/dist/v-org-tree.css'

import { VueJsonp } from 'vue-jsonp'
Vue.use(VueJsonp)
//富文本编辑器
import VueQuillEditor from "vue-quill-editor/src";
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(require('vue-moment'));
Vue.use(ElementUI, { size: 'mini' })
// 实际打包时应该不引入mock
/* eslint-disable */
// if (process.env.NODE_ENV !== 'production') require('@/mock')

Vue.use(iView, {
  i18n: (key, value) => i18n.t(key, value)
})

// 自定义全局组件 （按钮权限显示）
import { showRule } from "_c/custom-components";
Vue.component('showRule', showRule)
Vue.use(TreeTable);
Vue.use(VOrgTree);
Vue.use(VueQuillEditor);
Vue.use(require('vue-moment'));
/**
 * @description 注册admin内置插件
 */
installPlugin(Vue)
/**
 * @description 生产环境关掉提示
 */
Vue.config.productionTip = false
/**
 * @description 全局注册应用配置
 */
Vue.prototype.$config = config
Vue.prototype.$axios = axiosHttp
/**
 * 注册指令
 */
importDirective(Vue)
Vue.directive('clickOutside', clickOutside)

/* eslint-disable no-new */
const baseUrl = process.env.NODE_ENV === "development"? config.baseUrl.dev: config.baseUrl.pro;
const baseImgeUrl = process.env.NODE_ENV === "development" ? config.baseImgUrl.dev : config.baseImgUrl.pro;
axiosHttp(baseUrl+"/admin/index/getWebConfig").then((response) => {
    localStorage.setItem("website_config", JSON.stringify(response));
    const faviconUrl = baseImgeUrl + response.favicon_img;

    // 创建 <link> 元素
    const link = document.createElement("link");
    link.rel = "icon";
    link.href = faviconUrl;

    // 添加 <link> 元素到 <head> 中
    document.head.appendChild(link);

    /* eslint-disable no-new */
    new Vue({
      created() {},
      el: "#app",
      router,
      i18n,
      store,
      render: (h) => h(App),
    });
  }).catch((error) => {
    console.error("获取配置信息错误", error);
  });
